package com.qidianit.task.controller;

import com.qidianit.task.pojo.Project;
import com.qidianit.task.service.ProjectService;
import com.qidianit.task.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author hitsune
 * @Company kafu chino
 * @Description
 * @Time 2024/9/5 下午 4:45
 */
@RestController
@RequestMapping("/project")
@CrossOrigin
public class ProjectController {
    @Autowired
    private ProjectService projectService;
    // 这里没有使用@RequestBody
    @GetMapping("/list")
    public QdResult list(Project project, @RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "10")int limit){
        return projectService.selectByPage(project,page,limit);
    }
    @PutMapping("/delete/{projectId}")
    public void deleteProject(@PathVariable String projectId){
        projectService.deleteByProjectId(projectId);
    }
    @GetMapping("search/{projectId}")
    public Project selectOneByProjectId(@PathVariable String projectId){
        return projectService.selectOneByProjectId(projectId);
    }
    @PutMapping("/save/{projectId}")
    public void saveProject(@PathVariable String projectId,@RequestBody Project project){
        project.setProjectId(projectId);
        projectService.saveProject(project);
    }
    @PutMapping("/pigeonhole/{projectId}")
    public void pigeonProject(@PathVariable String projectId){
        projectService.pigeonholeProject(projectId);
    }

    @PostMapping("/publish")
    public void publish(String[] projectIds){
        projectService.publishProject(List.of(projectIds));
    }

    @PostMapping("/batch/pig")
    public void batchPig(String[] projectIds){
        projectService.batchPigProject(List.of(projectIds));
    }
    @PostMapping("/batch/del")
    public void batchDel(String[] projectIds){
        projectService.batchDelProject(List.of(projectIds));
    }

    @PutMapping("/recover/{projectId}")
    public void recoverProject(@PathVariable String projectId){
        projectService.recoverProject(projectId);
    }
    @PostMapping("/batch/recover")
    public void batchRecover(String [] projectIds){
        projectService.batchRecoverProject(List.of(projectIds));
    }
    @GetMapping("/list/del")
    public QdResult selectDelList(Project project, @RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "10")int limit){
        return projectService.selectDelList(project,page,limit);
    }
    @GetMapping("/list/get")
    public QdResult getProjectById(String projectId){
        return projectService.getProjectById(projectId);
    }
    @GetMapping("/sum/task")
    public Long sumTaskNum(String projectId){
        return projectService.sumTaskNum(projectId);
    }
    @GetMapping("/count")
    public QdResult countProject(Long userId){
        return projectService.countProject(userId);
    }
}
